package marchsoft.modules.four.h5.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import marchsoft.modules.four.common.entity.SafeCase;
import marchsoft.modules.four.common.entity.SafeType;
import marchsoft.modules.four.common.entity.Slideshow;
import marchsoft.modules.four.common.entity.StudyData;
import marchsoft.modules.system.entity.Dept;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 首页 mapper 层
 */
public interface HomeMapper extends BaseMapper<Object> {
	@Select("select * from e_study_data where safe_type_id=#{id}")
	List<StudyData> selectEstudyByid( long safeTypeId);
	//查询所有轮播图信息
	@Select("SELECT * FROM e_slideshow")
	List<Slideshow>  SelectESlideshowAll();


	//根据id查询文章详细信息
	@Select("SELECT * FROM e_study_data WHERE id = #{id}")
	List<StudyData> SelectEStudyDataFrontById(@Param("id") long id);

	//所有部门查询
	@Select("SELECT * FROM sys_dept WHERE is_deleted=0")
	List<Dept> selectAllDept();

	//点赞
	@Update("UPDATE e_study_data SET tags = tags + 1 WHERE id = #{id}")
	int updateEStudyDataFrontLike(@Param("id") long id);

	//取消点赞
	@Update("UPDATE e_study_data SET tags = tags - 1 WHERE id = #{id}")
	int updateEStudyDataFrontUnLike(@Param("id") long id);

	//踩
	@Update("UPDATE e_study_data SET dislike = dislike + 1 WHERE id = #{id}")
	int updateEStudyDataFrontDislike(long id);

	//取消踩
	@Update("UPDATE e_study_data SET dislike = dislike - 1 WHERE id = #{id}")
	int updateEStudyDataFrontUnDislike(long id);

	//查询所有分类信息
	@Select("SELECT * FROM e_safe_type")
	List<SafeType> selectESafeTypeFrontAll();

	//今日推荐
	@Select("SELECT * FROM e_study_data LIMIT #{little},10")
	List<StudyData> selectEStudyDataFrontDaily(@Param("little") int little);

	//经典案例
	@Select("SELECT * FROM e_safe_case LIMIT #{little},10")
	List<SafeCase> selectESafeCaseFrontAll(@Param("little") int little);

	//看了看
	@Update("UPDATE e_study_data SET page_view = #{count} WHERE id = #{id}")
    int updateEStudyDataFrontRead(@Param("id") long id, @Param("count") int count);
}
